package com.yt.sys.server.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yt.sys.models.entity.SysRolePerm;
import com.yt.sys.models.service.ISysRolePermService;
import com.yt.sys.server.mapper.SysRolePermMapper;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@DubboService(interfaceClass = ISysRolePermService.class)
public class SysRolePermServiceImpl extends ServiceImpl<SysRolePermMapper, SysRolePerm> implements ISysRolePermService {

    /**
     * 根据角色ID获取权限关联列表
     * @param roleId 角色ID
     * @return 权限关联列表
     */
    public List<SysRolePerm> getPermsByRoleId(Integer roleId) {
        QueryWrapper<SysRolePerm> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("role_id", roleId);
        return this.list(queryWrapper);
    }

    /**
     * 根据权限ID获取角色关联列表
     * @param permId 权限ID
     * @return 角色关联列表
     */
    public List<SysRolePerm> getRolesByPermId(Integer permId) {
        QueryWrapper<SysRolePerm> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("perm_id", permId);
        return this.list(queryWrapper);
    }

    /**
     * 删除角色的所有权限关联
     * @param roleId 角色ID
     * @return 是否操作成功
     */
    public boolean removePermsByRoleId(Integer roleId) {
        QueryWrapper<SysRolePerm> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("role_id", roleId);
        return this.remove(queryWrapper);
    }
}